package org.liaohailong.library.widget.interact.image

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import kotlinx.android.synthetic.main.layout_interact_image_view.view.*
import org.liaohailong.library.R
import org.liaohailong.library.image.glide.GlideApp
import org.liaohailong.library.widget.interact.IInteractView
import org.liaohailong.library.widget.interact.Message

/**
 * Author: liaohailong
 * Date: 2019/3/12
 * Time: 9:22 PM
 * Description: 图片互动插件
 **/
class InteractImageView(context: Context, attributeSet: AttributeSet?, defStyle: Int) :
        FrameLayout(context, attributeSet, defStyle), IInteractView {
    constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
    constructor(context: Context) : this(context, null)

    private var message: Message? = null
    private var callback: IInteractView.InteractViewCallback? = null

    init {
        LayoutInflater.from(context).inflate(R.layout.layout_interact_image_view, this, true)
    }

    override fun play(message: Message, callback: IInteractView.InteractViewCallback) {
        this.message = message
        this.callback = callback
        callback.onInteractViewPrepared(message)
        GlideApp.with(this)
                .load(message.url)
                .into(image_view)
        postDelayed({ callback.onInteractPlayComplete(message) }, 1000 * 6)
    }

    override fun release() {

    }
}